<?php
$this->headLink(array('href' => '/cms/styles/style.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headLink(array('href' => '/cms/styles/data-table.css', 'rel' => "stylesheet", 'type' => "text/css"));

$this->headScript()
	->appendFile('/cms/scripts/dojo/dojo.js','',array('djConfig'=> 'parseOnLoad:true, isDebug:false'))
	->setAllowArbitraryAttributes(true);

$this->headLink(array('href' => '/cms/scripts/shadowbox-3.0rc1/shadowbox.css', 'rel' => "stylesheet", 'type' => "text/css"));
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/shadowbox-3.0rc1/shadowbox.js');

$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/content.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/Popup.js');
$this->headScript(Zend_View_Helper_HeadScript::FILE,'/cms/scripts/TableData.js');
$this->headScript(Zend_View_Helper_HeadScript::SCRIPT,<<<EOD

dojo.require("dojo.fx");
dojo.require("dijit.Dialog");

var boxes = new Array();


var shadowbox_callback = function () {};

reset_shadowbox_callback = function () {
	shadowbox_callback = function () {};
} 

Shadowbox.init({
    players:    ['html', 'iframe', 'img', 'swf'],
    onClose: function() { shadowbox_callback() }
});

	
function doCollapse(el) {
	if (typeof boxes[el] == 'undefined'){
		boxes[el] = 0;
	}
	if (boxes[el]==1) {
		var currentAnimation = dojo.fx.wipeOut({node: el,duration: 300});
		boxes[el] = 0;
	} else {
		var currentAnimation = dojo.fx.wipeIn({node: el,duration: 300});
		boxes[el] = 1;
	}
    currentAnimation.play();
}		
		
		
EOD
);
?>
<link href="cms/styles/data-table.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.messageBox {
	border: 1px dashed #CCCCCC;
	margin-bottom: 12px;
}
.messageBoxHeader {
	background-color: #EBEBEB;
	height: 26px;
}
.messageBoxCollapse {
	padding: 5px;
	float: left;
}
.messageBoxControlls {
	padding: 5px;
	float: right;
}
.messageBoxTitle {
	padding: 5px;
	float: left;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.messageBoxBody {
	padding-top: 10px;
	padding-right: 5px;
	padding-bottom: 10px;
	padding-left: 31px;
	border-top-width: 1px;
	border-top-style: dashed;
	border-top-color: #CCCCCC;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	line-height: 16px;
	text-align: justify;
}
.messageBoxBodyControls {
	margin-top: 20px;
}

.active {
	color: #009933;
}

.nonactive {
	color: red;
}

.progress-status {
	background-color: #FF6600;
	height: 3px;
	float: left;
}
.progress-box {
	clear: both;
	float: none;
}
.progress-background {
	background-color: #999999;
	height: 3px;
	float: left;
}
.progress-value {
	float: left;
	clear: right;
	margin-top: -7px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	padding-left: 5px;
}
-->
</style>
</head>

<body class="modal">
<p class="stnd_font">
<a href="/cms/votes/edit/id/-1" rel="shadowbox;title=Редактирование голосования;height=500;width=600;player=iframe">
  <button class="okButton"><img src="/cms/images/plus.png" alt="" width="16" height="16" align="absmiddle" /> Добавить опрос</button>
</a>  
</p>
<?php 
    $cnt = $this->vote->length();
    for($i=0; $i<$cnt; $i++){
        $v = $this->vote->item($i);
        $v->Make();
?>

<div class="messageBox">
  <div class="messageBoxHeader">
    <div class="messageBoxControlls"><?php 
        if( $v->Status_id == 1 ){?>
            <span class="small active">Идет опрос</span>        
        <?php
        }else{ ?>
            <span class="small nonactive">Опрос приостановлен</span>        
    <?php }
    ?><a href="votes/edit/id/<?=$v->Vote_id?>" class="edit" rel="shadowbox;title=Редактирование голосования;height=500;width=600;player=iframe">
            <img src="/cms/images/document_pencil.png" width="16" height="16" />
        </a>
        <a href="/cms/votes/delvote/id/<?=$v->Vote_id?>"><img src="/cms/images/cross.png" width="16" height="16" /></a></div>
        <div class="messageBoxCollapse"><a href="javascript:;" 
            onclick="doCollapse('<?=$v->Vote_id?>')"><img src="/cms/images/plus_circle.png" alt="" width="16" height="16" /></a></div>
        <div class="messageBoxTitle"><?=$v->Work_until?> <a href="#"><?=$v->Question?></a></div>
  </div>  
  <div class="messageBoxBody" id="<?=$v->Vote_id?>" style="display:none">
    <ul>
      <?php
        //определяем коэффициент для масштабирования баров
        $max = 0;
        $c = $v->length();
        for($j=0; $j<$c; $j++){
            $a = $v->item($j);
            $vot = $a->votes;
            if( $j == 0 )
                $max = $vot;
            if( $max < $vot )
                $max = $vot;        
        }
        $koef = 0;
        if( $max ){ //вдруг вариантов пока еще нет
            $koef = 200/$max; //коэффициент для масштабирования. Длина баров - 200px
        }
        //выводим все варианты ответов
        for($j=0; $j<$c; $j++){
            $a = $v->item($j); //вариант ответа
            
      ?>
      <li>
        <?=$a->Answer?>
        <div class="progress-box">
          <div class="progress-status" style="width:<?=round($a->votes*$koef, 0)?>px"><img src="/cms/images/dot.gif" width="1" height="1" /></div>
          <div class="progress-background" style="width:<?=round(200 - $a->votes*$koef, 0)?>px"><img src="/cms/images/dot.gif" width="1" height="1" /></div>
          <div class="progress-value"><?=$a->votes?></div>
        </div>
        <div style="clear:both"></div>
      </li>
      <?php } //конец цикла с вариантами ответа
      ?>
    </ul>
    <div class="messageBoxBodyControls"><a href="#">
    <img src="/cms/images/document_pencil.png" width="16" height="16" align="absbottom" /></a> 
    <a href="votes/edit/id/<?=$v->Vote_id?>" class="edit" rel="shadowbox;title=Редактирование голосования;height=500;width=600;player=iframe">Редактировать</a> &nbsp;&nbsp; 
    <a href="/cms/votes/delvote/id/<?=$v->Vote_id?>">
        <img src="/cms/images/cross.png" width="16" height="16" align="absmiddle" />
    </a> 
        <a href="/cms/votes/delvote/id/<?=$v->Vote_id?>">Удалить</a></div>
  </div>
</div>
<?php 
    } //закончился цикл вывода опросов
?>
</body>

</html>
